package com.webex.ta.hydra.gui.action;

import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.gui.GuiPackage;
import com.webex.ta.hydra.gui.table.HydraTableModel;

import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-1
 * Time: 9:06:14
 */
public class EnableAction implements ActionHandler {
    private static Set<String> commands = new HashSet<String>();
	static {
		commands.add(ActionNames.TOGGLE_COMMENT);
	}

    public Set<String> getActionNames() {
        return commands;
    }

    public void doAction(ActionEvent e) {
        GuiPackage gp = GuiPackage.getInstance();
        HydraTableModel model = gp.getHydraTable().getModel();
        if (gp.getHydraTable().getSelectedRow() >= 0) {
            Command first = model.getCommandAt(gp.getHydraTable().getSelectedRow());
            boolean toEnable = !first.isEnabled();
            for (int row : gp.getHydraTable().getSelectedRows())
                model.getCommandAt(row).setEnabled(toEnable);
        }
        gp.getHydraTable().repaint();
    }
}
